<?php 
include 'method/win.php';

if(!isset($_SESSION['adminuser'])){
    show_msg("请先登录!","A-login.php");
}
if(isset($_GET['action'])){
    logout();
}
if(isset($_POST['submit'])){
    $_SESSION['scomment'] = $_POST['search-str'];
}
if(isset($_SESSION['scomment'])){
    $cmsql = "select * from weibo_comment where cm_content like '%".$_SESSION['scomment']."%'";
    $cmres = $conn->query($cmsql);
    $kidcmsql = "select * from weibo_kidcomment where kidcm_content like '%".$_SESSION['scomment']."%'";
    $kidcmres = $conn->query($kidcmsql);
}else{
    $cmsql = "select * from weibo_comment";
    $cmres = $conn->query($cmsql);
    $kidcmsql = "select * from weibo_kidcomment";
    $kidcmres = $conn->query($kidcmsql);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>删除评论、回复</title>
    <link rel="stylesheet" href="css/A-public.css">
    <link rel="stylesheet" href="../lib/bootstrap/css/bootstrap.css">
    <script src="../lib/jquery/jquery.js" type="text/javascript"></script>
</head>
<body style="background-color:#a1a3a6;">
<h3>删除评论、回复</h3>
<div class="user">

    <span class="span1">当前登录管理员为：<span class="username"><?php echo $_SESSION['adminuser']?></span></span>

    <a class="float-right leave" href="A-index.php?action=logout">退出</a>
    <a class="leave" href="A-index.php">返回</a>
</div>
<div class="well">
    <form class="search" method="post" action="">
        <input type="text" name="search-str" class="input-top" placeholder="请输入搜索内容">
        <button type="submit" name="submit" class="submit glyphicon glyphicon-search"/>
    </form>
</div>


<div class="btn-groups-1" role="group" aria-label="...">
    <div class="btn-group" role="group">
        <button id="nav-1" type="button" class="btn1 btn btn-default">评论</button>
    </div>
    <div class="btn-group" role="group">
        <button id="nav-2" type="button" class="btn1 btn btn-default">回复</button>
    </div>
</div>

<div class="table-div1 table-responsive choose-1" id="div1">
    <table class="table1 table-bordered">
        <tr class="">
            <td>序号</td>
            <td>id</td>
            <td>账号</td>
            <td>评论内容</td>
            <td>操作</td>
        </tr>
        <?php 
        $c_no = 1;
        if($cmres->num_rows){
            while($cmrows = $cmres->fetch_assoc()){
                echo "<tr class=''>";
                echo "<td>".$c_no."</td>";
                echo "<td>".$cmrows['cm_id']."</td>";
                echo "<td>".$cmrows['cm_author']."</td>";
                echo "<td>".$cmrows['cm_content']."</td>";
                echo "<td><button type='button' onclick=delCm(".$cmrows['cm_id'].") class='btn btn-default'>删除</button></td>";
                echo "</tr>";
                $c_no = $c_no+1;
            }
        }else{
            echo "<tr class=''>暂时没有相关评论</tr>";
        }
        ?>
    </table>
</div>




<div class="table-div2 table-responsive" id="div2">
    <table class="table2 table-bordered">
        <tr class="">
            <td>序号</td>
            <td>id</td>
            <td>账号</td>
            <td>回复内容</td>
            <td>操作</td>
        </tr>
        <?php 
        $k_no = 1;
        if($kidcmres->num_rows){
            while($kidcmrows = $kidcmres->fetch_assoc()){
                echo "<tr class=''>";
                echo "<td>".$k_no."</td>";
                echo "<td>".$kidcmrows['kidcm_id']."</td>";
                echo "<td>".$kidcmrows['kidcm_author']."</td>";
                echo "<td>".$kidcmrows['kidcm_content']."</td>";
                echo "<td><button type='button' onclick=delKidCm(".$kidcmrows['kidcm_id'].") class='btn btn-default'>删除</button></td>";
                echo "</tr>";
                $k_no = $k_no+1;
            }
        }else{
            echo "<tr class=''>暂时没有相关回复</tr>";
        }
        ?>
    </table>
</div>
<script>
    function delCm(id){
    	var tipDelCm = confirm("你确定要删除此条评论？")
    	if(tipDelCm){
    		$.ajax({
                type:"post",
        		url:"method/delcm_action.php",
        		data:{id: id},
        		success:function(data){
        				alert(data)
        		}
            });
    		location.reload();
    	}
    }
    function delKidCm(id){
    	var tipDelCm = confirm("你确定要删除此条回复？")
    	if(tipDelCm){
    		$.ajax({
                type:"post",
        		url:"method/delkidcm_action.php",
        		data:{id: id},
        		success:function(data){
        				alert(data)
        		}
            });
    		location.reload();
    	}
    }

    $("#nav-1").click(function () {
        $("#div1").removeClass("choose-1")
        $("#div2").removeClass("choose-1")
        $("#div1").addClass("choose-1")
    })
    $("#nav-2").click(function () {
        $("#div1").removeClass("choose-1")
        $("#div2").removeClass("choose-1")
        $("#div2").addClass("choose-1")
    })
</script>
</body>
</html>